import UIKit
import flutter_boost

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    // Make a button to call the showFlutter function when pressed.
    let button1 = UIButton(type:UIButton.ButtonType.custom)
    button1.addTarget(self, action: #selector(showFlutter1), for: .touchUpInside)
    button1.setTitle("Show Flutter! Boost", for: UIControl.State.normal)
    button1.frame = CGRect(x: 80.0, y: 210.0, width: 260, height: 40.0)
    button1.backgroundColor = UIColor.blue
    self.view.addSubview(button1)
      
    let button2 = UIButton(type:UIButton.ButtonType.custom)
    button2.addTarget(self, action: #selector(showFlutter2), for: .touchUpInside)
    button2.setTitle("Show Flutter! Flutter", for: UIControl.State.normal)
    button2.frame = CGRect(x: 80.0, y: 300, width: 260, height: 40.0)
    button2.backgroundColor = UIColor.blue
    self.view.addSubview(button2)
  }

  @objc func showFlutter1() {
      let pageName = "mainPage"

      
      let options = FlutterBoostRouteOptions()
      options.pageName = pageName
      options.arguments = ["data":"MainPageData"]
      
      options.completion = { completion in }
      options.onPageFinished = { dic in }
      let vc = FBFlutterViewContainer()
      vc?.setName(options.pageName, uniqueId: options.uniqueId, params: options.arguments, opaque: options.opaque)
      self.navigationController?.pushViewController(vc ?? FBFlutterViewContainer(), animated: false)
      print("goToFlutterVC1 end")
  }
    
    @objc func showFlutter2() {
        let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
        let flutterViewController =
            FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
        self.navigationController?.pushViewController(flutterViewController, animated: true)
        print("goToFlutterVC2 end")
    }
}
